Public Class account Private id As String Private name As String Private password As String Private balance As Double ' don't really know what to put in for a default account Public Sub New() name = "unknown" id = "invalid" password = "password" balance = 0 End Sub ' everything but balance - balance defaults to 0 Public Sub New(ByVal acctId As String, ByVal acctName As String, ByVal pw As String) name = acctName id = acctId password = pw balance = 0 End Sub ' all needed info supplied Public Sub New(ByVal acctId As String, ByVal acctName As String, ByVal pw As String, ByVal bal As Double) name = acctName id = acctId password = pw balance = bal End Sub ' could probably also use ones where account number and/or pin are generated rather than passed ' but don't need them for this example '' define properties, starting with acctNum Public Property acctNum() Get Return id End Get Set(ByVal Value) ' in a simple example we don't validate this ' in the real world there is probably a set of rules for what makes for a valid acct num ' probably also should check to make sure the acct num doesn't already exist id = Value End Set End Property Public Property custName() Get Return name End Get Set(ByVal Value) ' I don't think there is really a way to validate a customer name name = Value End Set End Property Public Property PIN() Get Return password End Get Set(ByVal Value) ' for simple example accept anything as valid ' in real world, may have rules password = Value End Set End Property Public Property bal() Get Return balance End Get Set(ByVal Value) ' I really don't want to make this available for anybody to change - I want them to go through, deposit, withdraw etc ' so I almost made the property private ' I want to allow negative balance because if the person overdraws the account, I don't want them to get away with it balance = Value End Set End Property '' now - more interesting methods ' Deposit - add money to the account - return true if successful, false otherwise ' problem would be if negative amount passed - don't want to allow withdrawl by calling ' deposit with negative amount Public Function deposit(ByVal amt As Double) As Boolean If amt <= 0 Then Return False Else balance = balance + amt End If Return True End Function ' withdraw - subtract money from account - return true if successful, false otherwise ' problem if amt is not positive or if not enough money in account ' if you want to allow overdraft, call forceWithdraw below Public Function withdraw(ByVal amt As Double) As Boolean If amt <= 0 Then Return False ElseIf amt > balance Then Return False Else balance = balance - amt Return True End If End Function ' force withdraw - subtract money from account, even allowing overdraft - return true if successful, false otherwise ' problem if amt is not positive Public Function forceWithdraw(ByVal amt As Double) As Boolean If amt <= 0 Then Return False Else balance = balance - amt Return True End If End Function ' account inquiry ' my way to allow controlled access to account balance ' somebody can see it - but to change it, they must deposit or withdraw Public Function acctInq() As Double Return balance End Function ' check of whether a passed string matches the account id of an account ' provided to push more capability into the class Public Function matchAcctNum(ByVal toMatch As String) As Boolean If id = toMatch Then Return True Else Return False End If End Function ' check out whether an account number and pin both match the passed values Public Function matchAcctNumNPIN(ByVal acct As String, ByVal pn As String) As Boolean If acct = id AndAlso pn = password Then Return True Else Return False End If End Function ' check out whether the current account and a passed account match on both acctnum and pin Public Function matchAccounts(ByVal toCompare As account) As Boolean If id = toCompare.id AndAlso password = toCompare.password Then Return True Else Return False End If End Function ' check out whether the current account and a passed account match on all attributes Public Function identicalMatchAccounts(ByVal toCompare As account) As Boolean If id = toCompare.id AndAlso password = toCompare.password _ AndAlso name = toCompare.name AndAlso balance = toCompare.balance Then Return True Else Return False End If End Function ' provides acctnum and name - nothing of privacy concern (pin and balance) Public Function privacyToString() Return id & "," & name End Function End Class